Fix updating the registry too often
authorAlex Crichton <alex@alexcrichton.com>
Mon, 8 Dec 2014 06:25:26 +0000 (22:25 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 8 Dec 2014 06:28:43 +0000 (22:28 -0800)
It turns out that the registry was being queried with git dependencies as well,
so this commit alters the core registry not query sources with dependencies that
did not originate from the source.

Closes #991

src/cargo/core/registry.rs
src/cargo/core/source.rs
tests/support/git.rs
tests/test_cargo_registry.rs

index 5ab42b30f381071600cb6525f522b4242231144b..1c6c592dfe6d050f2bb07a46086192e9f4606a90 100644 (file)
@@ -89,7 +89,7 @@ impl<'a> PackageRegistry<'a> {
         // source
         let mut ret = Vec::new();
 
-        for source in self.sources.sources_mut() {
+        for (_, source) in self.sources.sources_mut() {
             try!(source.download(package_ids));
             let packages = try!(source.get(package_ids));
 
@@ -283,8 +283,10 @@ impl<'a> Registry for PackageRegistry<'a> {
             // Ensure the requested source_id is loaded
             try!(self.ensure_loaded(dep.get_source_id()));
             let mut ret = Vec::new();
-            for src in self.sources.sources_mut() {
-                ret.extend(try!(src.query(dep)).into_iter());
+            for (id, src) in self.sources.sources_mut() {
+                if id == dep.get_source_id() {
+                    ret.extend(try!(src.query(dep)).into_iter());
+                }
             }
             ret
         } else {
index c811772792f3abc5d1f23dd6af52c3ce56c90d85..18bdf650f53538115b46d4bf997743928321444a 100644 (file)
@@ -327,7 +327,7 @@ pub struct SourceMap<'src> {
 pub type Sources<'a, 'src> = Values<'a, SourceId, Box<Source+'src>>;
 pub type SourcesMut<'a, 'src> = iter::Map<'static, (&'a SourceId,
                                                   &'a mut Box<Source+'src>),
-                                    &'a mut (Source+'src),
+                                    (&'a SourceId, &'a mut (Source+'src)),
                                     MutEntries<'a, SourceId, Box<Source+'src>>>;
 
 impl<'src> SourceMap<'src> {
@@ -374,7 +374,7 @@ impl<'src> SourceMap<'src> {
     }
 
     pub fn sources_mut<'a>(&'a mut self) -> SourcesMut<'a, 'src> {
-        self.map.iter_mut().map(|(_, v)| &mut **v)
+        self.map.iter_mut().map(|(k, v)| (k, &mut **v))
     }
 }
 
index 1216617b50d43cc1c31029cf80df218c0176604f..f41baf45118c18252e1f1f691ae201cff1599796 100644 (file)
@@ -1,7 +1,10 @@
 use std::io::{mod, fs, File};
 
+use url::Url;
 use git2;
 
+use support::path2url;
+
 pub struct RepoBuilder {
     repo: git2::Repository,
     files: Vec<Path>,
@@ -47,4 +50,6 @@ impl RepoBuilder {
         self.repo.commit(Some("HEAD"), &sig, &sig,
                          "Initial commit", &tree, &[]).unwrap();
     }
+
+    pub fn url(&self) -> Url { path2url(self.repo.path().dir_path()) }
 }
index 8bb32cbc2249642b0587b57a71f61f23bd0c10be..601587a0b2ca2eecf7b1e801ea539cb295610d85 100644 (file)
@@ -5,6 +5,7 @@ use support::{project, execs, cargo_dir};
 use support::{UPDATING, DOWNLOADING, COMPILING, PACKAGING, VERIFYING};
 use support::paths::{mod, PathExt};
 use support::registry as r;
+use support::git;
 
 use hamcrest::assert_that;
 
@@ -558,3 +559,52 @@ test!(updating_a_dep {
 ", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
    dir = p.url()).as_slice()));
 })
+
+test!(git_and_registry_dep {
+    let b = git::repo(&paths::root().join("b"))
+        .file("Cargo.toml", r#"
+            [project]
+            name = "b"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            a = "0.0.1"
+        "#)
+        .file("src/lib.rs", "");
+    b.build();
+    let p = project("foo")
+        .file("Cargo.toml", format!(r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            a = "0.0.1"
+
+            [dependencies.b]
+            git = '{}'
+        "#, b.url()))
+        .file("src/main.rs", "fn main() {}");
+    p.build();
+
+    r::mock_pkg("a", "0.0.1", &[]);
+
+    p.root().move_into_the_past().unwrap();
+    assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
+                execs().with_status(0).with_stdout(format!("\
+{updating} [..]
+{updating} [..]
+{downloading} a v0.0.1 (registry file://[..])
+{compiling} a v0.0.1 (registry [..])
+{compiling} b v0.0.1 ([..])
+{compiling} foo v0.0.1 ({dir})
+", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
+   dir = p.url()).as_slice()));
+    p.root().move_into_the_past().unwrap();
+
+    println!("second");
+    assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
+                execs().with_status(0).with_stdout(""));
+})